/*
 * @Author: szx
 * @Date: 2022-06-09 14:52:38
 * @LastEditTime: 2022-06-09 14:56:49
 * @Description:
 * @FilePath: \leetcode\面试题\16\17\17.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function (nums) {
    let max = 0,
        cnt = 0;
    for (let num of nums) {
        cnt += num;
        if (cnt < 0) cnt = num;
        if (cnt > max) max = cnt;
    }
    return max;
};
